package com.tgy.leetcode;

import java.util.Arrays;

/**
 * @Author: tgy
 * @Date: 12/31/20 10:24 AM
 *
 *
 *  https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons/
 */
public class _452_用最少数量的箭引爆气球 {


    public int findMinArrowShots(int[][] points) {

        if (points == null || points.length == 0) {

            return 0;
        }

        Arrays.sort(points,(o1, o2) -> {


            // 不要使用 o1[1] - o2[1] ，结果有可能溢出int范围
            return Integer.compare(o1[1],o2[2]);
        });

        int count = 1;
        int end = points[0][1];

        for (int i = 1; i < points.length; i++) {

            if (points[i][0] > end) {

                count++;
                end = points[i][1];
            }
        }

        return count;
    }

}
